<!DOCTYPE html>
<html>
<head>
    <title>Capacitor with Two Dielectrics</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f7f7f7;
        }
        canvas {
            border: 1px solid #ccc;
            background-color: #fff;
        }
    </style>
</head>
<body>
    <canvas id="capacitorCanvas" width="500" height="450"></canvas>
    <script>
        const canvas = document.getElementById('capacitorCanvas');
        const ctx = canvas.getContext('2d');

        // Define drawing parameters based on the image analysis
        const cx = canvas.width / 2;
        const mainY = 180; // Vertical center of the capacitor body
        const totalWidth = 320;
        const height = 100; // Plate separation / dielectric height
        const wireLength = 80;

        // Based on the problem S₁/S₂ = 3, the width ratio w₁/w₂ is also 3
        const width1 = totalWidth * (3 / 4);
        const width2 = totalWidth * (1 / 4);

        const startX = cx - totalWidth / 2;
        const startY = mainY - height / 2;
        const endY = mainY + height / 2;
        const divisionX = startX + width1;

        // --- 1. Draw Dielectrics ---
        // Dielectric ε₁ (lighter gray)
        ctx.fillStyle = '#f0f0f0';
        ctx.fillRect(startX, startY, width1, height);

        // Dielectric ε₂ (darker gray)
        ctx.fillStyle = '#e0e0e0';
        ctx.fillRect(divisionX, startY, width2, height);

        // --- 2. Draw Capacitor Structure Outline ---
        // The capacitor plates and end caps are drawn as a single rectangle outline
        ctx.strokeStyle = 'black';
        ctx.lineWidth = 2;
        ctx.strokeRect(startX, startY, totalWidth, height);

        // Draw the division line between the two dielectrics
        ctx.beginPath();
        ctx.moveTo(divisionX, startY);
        ctx.lineTo(divisionX, endY);
        ctx.stroke();

        // --- 3. Draw Connecting Wires ---
        ctx.lineWidth = 1.5;
        ctx.beginPath();
        // Top wire extending upwards from the center of the top plate
        ctx.moveTo(cx, startY);
        ctx.lineTo(cx, startY - wireLength);
        // Bottom wire extending downwards from the center of the bottom plate
        ctx.moveTo(cx, endY);
        ctx.lineTo(cx, endY + wireLength);
        ctx.stroke();

        // --- 4. Draw Labels ---
        ctx.fillStyle = 'black';
        ctx.textAlign = 'center';
        ctx.textBaseline = 'middle';

        // Label for dielectric 1: ε₁
        ctx.font = 'italic 28px "Times New Roman"';
        ctx.fillText('ε₁', startX + width1 / 2, mainY);

        // Label for dielectric 2: ε₂
        ctx.font = 'italic 28px "Times New Roman"';
        ctx.fillText('ε₂', divisionX + width2 / 2, mainY);

        // --- 5. Draw Caption ---
        // The text "习题 7-54 图" (Exercise 7-54 Figure)
        ctx.font = '22px "SimSun", "Songti SC"'; // Standard Chinese fonts
        ctx.fillText('习题 7-54 图', cx, endY + wireLength + 50);

    </script>
</body>
</html>